Community Curator/Source/TSWRes Tool1
ToolRes = {} function math.round(N) if (N - math.floor(N)) < .5 then return math.floor(N) end return math.ceil(N) end function OCTouch(TX, TY) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) CorTab = ObjSelected if PopitClosed or Undo then ObjSelected = nil CorTab = nil PopitCuTool = nil return true end local TDirH, TDirV = TDPad(64, SizeY-96,TX,TY) CamX, CamY = CamX + TDirH, CamY + TDirV if TDirH 0 and TDirV 0 then if LTV + TherAdd <= MT then GT.SaveUndo() ObjTab#ObjTab+1 = GT.CreObjTab(CorTab, TX + CamX, TY - CamY, Size, TherAdd, false, SelectedMaterial) LTV = LTV + TherAdd PopitRes.PlaceSound() else PopitRes.UnavailSound() end end end function ToolRes.ObjectCursor(CorTab) Undo = false PopitCuTool = "Object Cursor" TherAdd, Size = 0, ObjRes.SizeTabCorTab or 16 local Resizeable = ObjRes.SizeTabCorTab nil ObjSelected = CorTab if type(CorTab) "table" then TherAdd = 10*#CorTab else TherAdd = ObjRes.TherTabCorTab or 0 end for i=1, math.huge do GT.DrawCMFrame() draw.doevents() local TX, TY = draw.tracktouches(Nil, CamMove, OCTouch) if PopitCuTool nil then GT.SaveUndo() return end collectgarbage() end end function FixObjCorn(CorTab) local StartX, EndX = math.huge, 0 local StartY, EndY = math.huge, 0 for k,v in pairs(CorTab) do StartX = math.min(v1, StartX) StartY = math.min(v2, StartY) end for k,v in pairs(CorTab) do v1 = v1 - (StartX) v2 = v2 - (StartY) end for k,v in pairs(CorTab) do EndX = math.max(v1, EndX) EndY = math.max(v2, EndY) end for k,v in pairs(CorTab) do v1 = ((v1 / math.max(EndX, EndY))) v2 = ((v2 / math.max(EndX, EndY))) end return StartX, StartY, EndX, EndY end function FixObjCorn2(CorTab, Size) local EndX = 0 local EndY = 0 for k,v in pairs(CorTab) do EndX = math.max(v1, EndX) EndY = math.max(v2, EndY) end for k,v in pairs(CorTab) do v1 = (v1*Size) v2 = (v2*Size) end return EndX, EndY end function FixObj(ObjTab) local StartX, StartY, EndX, EndY = FixObjCorn(ObjTab"CorTab") ObjTab"Size" = (ObjTab"Size" * math.max(EndX, EndY)) ObjTab"X" = ObjTab"X" + StartX --(math.max(EndX, EndY)) ObjTab"Y" = ObjTab"Y" + StartY -- (math.max(EndX, EndY)) end function FixObj2(ObjTab) local EndX, EndY = FixObjCorn2(ObjTab"CorTab", ObjTab"Size") ObjTab"Size" = 1 ObjTab"X" = ObjTab"X" - (math.max(EndX, EndY)*.5) ObjTab"Y" = ObjTab"Y" + (math.max(EndX, EndY)*.5) end function ObjSel(TX, TY) --if TX nil then -- return TX, TY --end local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) if PopitClosed then ToolClosed = true return end for k,v in pairs(ObjTab) do local ObjTap = TRec(v"X"- 16 -CamX, v"Y"- 16 +CamY, (v"X" + v"Size")+ 4-CamX, (v"Y" + v"Size")+ 4+CamY, TX, TY) if ObjTap true then if k > 4 then ObjSelected = k end end end end function CETouch(TX, TY) --print("Touched "..TX, TY) assert(TX) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) if ObjSelected nil then if PopitClosed then ToolClosed = true return end ObjSel(TX, TY) return TX, TY elseif CorSel nil then if PopitClosed then Object = ObjTabObjSelected FixObj(Object) Object"TVal" = #Object"CorTab" * 10 GT.FixIncLTV() ObjSelected = nil Fixed = nil return end end Object = ObjTabObjSelected assert(ObjSelected, "ObjSelected is missing") if CorSel ~= nil then CETouchC(TX, TY) return TX, TY end if type(Object"CorTab") ~= "table" then Object"CorTab" = end assert(ObjSelected ~= nil) assert(type(Object"CorTab") "table") if type(Object"CorTab") "table" and not Fixed then FixObj2(Object) Fixed = true end CorSel = nil local SB = 24 local Size = Object"Size" for k, v in ipairs(Object"CorTab") do local IsSel = TRec(((v1*Size)-16)+(Object"X"), ((v2*Size)-16)+(Object"Y"), ((v1*Size)+16)+(Object"X"), ((v2*Size)+16)+(Object"Y"), TX+CamX, TY-CamY) if IsSel then CorSel = k --print("CorSel"..CorSel) return TX, TY end end if CorSel nil then CorSel = #Object"CorTab"+1 end return TX, TY end function CETouchC(TX, TY) local PopitClosed = TRec(SizeX-96, SizeY-96, SizeX-32, SizeY-32,TX,TY) CorTab = ObjTabObjSelected CorTab =CorTab"CorTab" if PopitClosed and CorTabCorSel ~= nil then --print("Deleting "..tostring(CorSel)) table.remove(CorTab, CorSel) CorSel = nil PopitRes.DeleteSound() return elseif PopitClosed and CorTabCorSel nil then CorSel = nil return end CorTabCorSel = {} SCor = CorTabCorSel if not Grid then SCor1 = (-((-TX+(Object"X"))/Object"Size"))+(CamX/Object"Size") SCor2 = (-((-TY+(Object"Y"))/Object"Size"))- (CamY/Object"Size") else SCor1 = math.round((-((-TX+(Object"X"))/Object"Size"))+(CamX/Object"Size")) SCor2 = math.round((-((-TY+(Object"Y"))/Object"Size"))- (CamY/Object"Size")) end --print((TX+(Object"X"))/Object"Size") PopitRes.PlaceSound() CorSel = nil end function CornerShow() if ObjSelected nil then return end local Object = ObjTabObjSelected local CorTab = Object"CorTab" local Cor = CorTabCorSel --print("Corner "..CorSel, "X: "..Cor1, "Y: "..Cor2) if Cor ~= nil then draw.beginframe() local Size = Object"Size" draw.fillcircle(((Cor1*Size)+(Object"X"))-CamX, ((Cor2*Size)+(Object"Y"))+CamY, 16, PlayCol1) --print("CorSel"..CorSel) draw.endframe() end end function ToolRes.CorEditor() PopitCuTool = "Corner Editor" ObjSelected = nil Mode = 0 draw.tracktouches(Nil, CamMove, CETouch) for i=1, math.huge do GT.DrawCMFrame() if CorSel ~= nil then CornerShow() end draw.doevents() if ToolClosed then return end --[ObjSelected nil then if TDirH 0 and TDirV 0 then end else local Object = ObjTab[ObjSelected print(ObjSelected) local TDirH, TDirV = TDPad(64, SizeY-96,TX,TY) CamX, CamY = CamX + TDirH, CamY + TDirV if PopitClosed then table.remove(ObjTab, ObjSelected) PopitRes.DeleteSound() end if TDirH 0 and TDirV 0 then if CorSel nil then CETouch(TX, TY) else CETouchC(TX, TY) end end end]] collectgarbage("stop") end end PopitRes.ObjectCursor = ToolRes.ObjectCursor PopitRes.CorEditor = ToolRes.CorEditor require "TSWRes Tool2" return